import { ApiProperty, getSchemaPath } from '@midwayjs/swagger';
import { getSchema, Rule, RuleType } from '@midwayjs/validate';
import { Column, Entity, PrimaryColumn } from 'typeorm';

@Entity({
  name: 'goodsItems',
  synchronize: false,
})
export class GoodsItem {
  @ApiProperty({ example: 0 })
  @Rule(RuleType.number())
  @PrimaryColumn()
  goodsItemId: number;
  @ApiProperty({ example: '' })
  @Rule(RuleType.string().allow('').allow(null))
  @PrimaryColumn()
  goodsFk: string;
  @ApiProperty({ example: '' })
  @Rule(RuleType.string().allow('').allow(null).required())
  @Column()
  lebal: string;
  @ApiProperty({ example: 0 })
  @Rule(RuleType.number().allow('').allow(null).required())
  @Column({
    type: 'decimal',
    precision: 18,
    scale: 2,
    transformer: {
      to(data: number): number {
        return data;
      },
      from(data: string): number {
        return parseFloat(data);
      },
    },
  })
  price: number;
  @ApiProperty({ example: '' })
  @Rule(RuleType.string().allow('').allow(null).required())
  @Column()
  img: string;
}
@Entity('goods')
export class Goods {
  @PrimaryColumn()
  @Rule(RuleType.string())
  goodsId: string;
  @ApiProperty({
    type: 'string',
    example: '衣服',
  })
  @Column()
  @Rule(RuleType.string().required())
  name: string;
  @ApiProperty({
    type: 'array',
    items: {
      $ref: getSchemaPath(GoodsItem),
    },
  })
  @Rule(RuleType.array().items(getSchema(GoodsItem)).required())
  items: Array<GoodsItem> = [];
}
export class GoodsQuery {
  @ApiProperty({
    type: 'string',
    example: '',
  })
  @Rule(RuleType.string().allow(null).allow(''))
  name: string;
  @ApiProperty({
    type: 'number',
    example: 1,
  })
  @Rule(RuleType.number().min(1).required())
  pageIndex: number;
  @ApiProperty({
    type: 'number',
    example: 20,
  })
  @Rule(RuleType.number().min(1).required())
  pageSize: number;
  // @ApiProperty({
  //   type: 'string',
  //   example: '',
  // })
  // @Rule(RuleType.string().allow(null).allow(''))
  // DateBegin: string;
  // @ApiProperty({
  //   type: 'string',
  //   example: '',
  // })
  // @Rule(RuleType.string().allow(null).allow(''))
  // DateEnd: string;
}
// {
//   "name": "衣服",
//   "items": [
//     {

// "lebal":"1",
// "price":"1",
// "img":"1"
// },
//   {

// "lebal":"2",
// "price":"2",
// "img":"2"
// }
//   ]
// }
